Skip to content

make rasdaemon more modular and add support to use other databases - #258

Merged
mchehab merged 148 commits into
masterfrom
next
Aug 27, 2026
Merged

make rasdaemon more modular and add support to use other databases#258
mchehab merged 148 commits into
masterfrom
next

Conversation

@mchehab

@mchehab mchehab commented Aug 8, 2026

Copy link
Copy Markdown
Owner

In preparation for rasdaemon version 1.0.0, improve its internal architecture.

Goals:

  • make rasdaemon modular;
  • allow using more databases;
  • add unit tests

Updates:

  • mysql support added;
    • mariadb variant with mariadb-connector is also supported;
  • postgresql support added;
  • sqlite3, mysql and postgresql unit tests passed;
  • converted to use meson instead of auto-tools;
  • CI jobs adjusted to use meson and all off them passes;
  • Improved README.md file content;
  • rasdaemon now reads its env file from /etc/sysconfig/rasdaemon (or via a --config parameter);
  • rasdaemon itself now properly loads the right DB based on an env var.
  • rasdaemon tested and it is working with sqlite3, mysql and postgres.
  • when postgres or mysql/mariadb is used, add a hostname on all tables.

TODO:

  • ras-mc-ctl currently supports only sqlite3;
  • except for the primary key, no indexes are generated. Should we do it at table creation time or when ras-mc-ctl is used the first time with a new table?

PR seems to be ready for merge.

I appreciate feedbacks and PRs against the next branch to help with the redesign.

mchehab added 10 commits August 8, 2026 13:36
Right now, the DB logic was written to support only sqlite3.
As we're aiming to add support for other databases, use a more
generic way to describe DB fields.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Convert sqlite3-specific bindings into a generic one inside
ras-record, to allow adding support later for other databases.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
In preparation for adding support to other databases, don't
keep any sqlite3 stuff outside ras-record.

For now, we'll keep HAVE_SQLITE3 as an intermediate step,
as right now the only SQL supported database is sqlite3.

In the future, this will be broken on two separate fields,
and the checks inside each rasdaemon file will disapear, as
the SQL backend core will take care of it.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Those should be 644, not 755.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Right now, rasdaemon is only partially modular: at build time,
each individual feature can be selected and added, but the code
requires lots of ifdefs.

This worked fine at the beginning when there weren't much options,
but now the code has lots of optional features. Use a more modular
design by adding a module register logic.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
As the project grew, there are now too much files at the
core directory, making harder to maintain.

Move them to subdirs.

No functional changes.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Make it more generic, aiming to allow automatic module load
via __attribute__((constructor)).

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
As we're aiming to let module registration to happen in any
order, make the logic deterministic by inserting modules in
alphabetic order.

This makes insert being O(n) instead of O(1), but performance
here is not a problem.

While here, fix a bug when checking if allocation succeded.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
While the code compiles, it fails at the test cases.

Fix the issues.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Add unit tests to check if modules logic works.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
mchehab added 4 commits August 9, 2026 11:57
Allow modules to optionally set a private data and ensure that
cleanup will receive enough context.

This is needed to check modules functionality via unit tests,
and could help to ensure that cleanup will do the right thing.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Ensure that init and cleanup logic will work as expected.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Instead of relying on manual conference, check programaticly
if module cleanups will happen at the expected way.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
When doing unit tests, it doesn't make any sense to write at
syslog. Also, on success, the normal behavior is to just mask
the error output.

Implement support for it and modify tests/test-modules to
use such feature.

After such change, a successful run will be cleaner:

	Testing modules functionality:
	01/06:   Running NULL entry
	02/06:   Running single module
	03/06:   Running modules in order
	04/06:   Running modules out of order
	05/06:   Running multiple levels
	06/06:   Running init/cleanup
	All module registration tests passed.

And if the logs are always shown, there will be a tab on
each new line, which will produce a better visual output
as well:

	Testing modules functionality:
	01/06:   Running NULL entry
        module entry is missing!
	02/06:   Running single module
	03/06:   Running modules in order
	04/06:   Running modules out of order
	05/06:   Running multiple levels
	06/06:   Running init/cleanup
	        module alpha enabled
	        module charlie enabled
	        module foxtrot enabled
	        module delta enabled
	        module echo enabled
	        module beta enabled
	All module registration tests passed.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Move all sqlite3-specific logit to db/ras-db, preparing the code
to support other databases in the future.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
change the namespace for all database-related ops.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Use kernel-doc style markups to document the database
generic interface.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
The code there contains only sqlite3 specifics. Rename it to
better reflect its content.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
In preparation to support other database types, add an
abstraction layer.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
As the idea is to make the logic more modular to give more
flexibility and remove ifdef code from rasdaemon, move
the DB backend initialization to be done via module register.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Forgot to add ras-db code on a previous commit.

While here, update .gitignore.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
This is useful for unit tests.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
@mchehab
mchehab force-pushed the next branch 2 times, most recently from 45e9484 to 38bf93a Compare August 11, 2026 12:01
Add a way to check if db-sqlite3 implementation is working.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
mchehab added 30 commits August 27, 2026 07:14
When creating or altering table, add index for timestamp
and hostnames, as those are the fields which will likely
need more.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Instead of duplicating everything inside ras-mc-ctl.8.in,
dynamically create man pages from what's there at ras-mc-ctl.

That helps keeping it sane from maintainership PoV.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
As rasdaemon now create index automatically at table creation
or alter table time, there's no need to create it on python,
maybe except if one is running it with a database created with
an old version.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
A previous change during the change to a more generic DB backend
ended dropping mc_event table creation/preparation.

Re-add it.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
There are some minor discrepancies between parameter handling
on rasdaemon and ras-mc-ctl. Address them and make both support
unix sockets.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Do some adjustments at parameter handling and change the default
database to rasdaemon. The rasdaemon_test database is meant to be
used only at unittests and Github actions.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
--until currently picks until last day at midnight. Increment
day by one to select until the date at midnight.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
After code refactoring, such features were removed. Re-add them.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Allow controlling better the database queries

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
It is useful to have a general view about the number of errors
per table.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Allow using a single letter for all command line args.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Add functionality tests for each rasdaemon feature

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
The changeset 6c1bc90 ("Reorganize source tree") reorganized
rasdaemon tree, grouping similar features on separate dirs.
Yet, the job was not perfect.

Now that we're using meson, and in preparation to make features
modular, do fine adjustments:

- ensure that all events are inside an events dir;
- add an event's dir for RISC-V;
- the modules direction now contain only report logic.

No functional changes.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Now that rasdaemon directories are in better shape, reorder
includes, placing each group in alphabetical order.

While here, drop handle_erst_mce() from ras-erst.h, as this is
an static function.

No functional changes.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
The current logic will bail out if rasdaemon is built without
DB support, as there won't be a ras-mc-ctl db command.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
CI tests are currently failing because of ISO-8601 offset
format. Use one that works with older versions.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
When building distro-specific packages, it is interesting to
select them per architecture.

Keep the default to build for all architectures, as this makes
easier to test rasdaemon, but, at the Fedora package, select
them depending on the target architecture.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Do an integrated tests between C and python code by adding
per-database tests to insert data on a database and checking if
ras-mc-ctl is getting data right.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Several new files are missing a copyright line; others have them
with gpl-2.0 or later. Uniform them for all new files.

While here, stop using GPL-2.0, as this was deprecated in
SPDX 3.0, using, instead, GPL-2.0-only.

No functional changes and no actual license changes, as the
new files were always aimed to be GPL-2.0-only.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
We don't want to run unittests on all builds, as this is is
a development-specific target.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
using sqlite3_bind_text() causes the blob to be badly displayed
by ras-mc-ctl.

Fix it by using the proper sqlite3_bind_blob() function.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Add some logic on such tests to avoid problems if DB
support is not found.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Ensure that the userspace tool will use the same parameters
as the C file when running unittests.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Those were added during test creation, but they don't do anything
useful. Drop them.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Simplify the code and ensure that fields will be properly be
filled.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Ensure that all archs will build fine.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Building Fedora with rawhide is failing, probably due to some
unstable changes. So, instead, use a fixed version for it.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant